<template>
  <FrontSideTable
    ref="fileTable"
    dataUrl="/bridge/bridgeFile/getListByBridgeId"
    :dataParam="{bridgeId:currentBridge.id}"
    addUrl="/bridge/bridgeFile/add"
    editUrl="/bridge/bridgeFile/edit"
    deleteUrl="/bridge/bridgeFile/delete"
    :tableTitle="'桥梁档案管理 / '+currentBridge.roadNo+' '+this.currentBridge.name"
    :columns="columns"
    searchHint="输入关键字搜索，多个关键字用空格隔开"
    :searchProps="searchProps"
    :form="form"
    formDialogSize="tiny"
    :loadingForm="loadingForm"
    :rules="rules"
    @beforeAdd="handleAdd"
    @beforeEdit="handleEdit"
    @onBack="handleBack"
    canBack>

    <!--前面的展开列-->
    <template slot="beforeColumns">
      <el-table-column type="expand">
        <template slot-scope="scope">
          <FileList
            :defaultList="scope.row.bridgeFilePathList"
            uploadUrl="/bridge/bridgeFile/uploadBridgeFile"
            downloadUrl="/bridge/bridgeFile/downloadBridgeFile"
            :uploadParam="scope.row"
            deleteUrl="/bridge/bridgeFile/deleteBridgeFilePath"
            @onClose="fileList=>scope.row.bridgeFilePathList=fileList">
          </FileList>
        </template>
      </el-table-column>
    </template>

    <!--表单对话框-->
    <template slot="form">
      <el-form-item label="文件名称">
        <el-input v-model="form.fileName" placeholder="请输入文件名称"></el-input>
      </el-form-item>
      <el-form-item label="文件类型">
        <el-select v-model="form.fileTypeId" style="width: 100%" filterable>
          <el-option v-for="item of fileTypeList" :key="item.id" :value="item.id" :label="item.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="出版日期">
        <el-date-picker v-model="form.publicationDate" style="width: 100%;" align="right" type="date" placeholder="请选择日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="档案编号">
        <el-input v-model="form.fileNumber" placeholder="请输入档案编号"></el-input>
      </el-form-item>
      <el-form-item label="是否齐全">
        <el-switch v-model="form.isCompletion" on-text="是" off-text="否" :on-value="1" :off-value="0"></el-switch>
      </el-form-item>
    </template>
  </FrontSideTable>
</template>

<script>
  import FrontSideTable from "./FrontSideTable.vue";
  import FileList from "./FileList.vue";
  import {doGet} from "../../../assets/js/utils/RequestUtils";

  const FILE_TYPE_URL = "/bridge/bridgeFile/getFileTypeList";

  export default {
    name:"FileManagement",
    props:{
      currentBridge:{
        type:Object,
        required:true
      }
    },
    data() {
      return {
        fileTypeList:[],
        columns:[
          {prop:"fileTypeName", label:"文件类型"},
          {prop:"fileName", label:"文件名称"},
          {prop:"fileNumber", label:"档案号"},
          {prop:"publicationDateStr", label:"出版日期"},
          {prop:"fileDateStr", label:"建档年月"}
        ],
        searchProps:["fileTypeName", "fileName", "fileNumber", "isCompletion"],
        form:{
          fileTypeId:"",
          publicationDate:"",
          isCompletion:1
        },
        loadingForm:false,
        rules:{}
      }
    },
    methods:{
      handleAdd() {
        this.form.bridgeId = this.currentBridge.id;
      },
      handleEdit(data) {
        this.form = {...data};
      },
      handleBack() {
        this.$emit("onFileBack");
      },
      fetchFileTypeList() {
        doGet(FILE_TYPE_URL, {component:this}).then(response=>this.fileTypeList = response);
      }
    },
    created() {
      this.fetchFileTypeList();
    },
    components:{FrontSideTable, FileList}
  }
</script>



// WEBPACK FOOTER //
// FileManagement.vue?640e7578
